backlinks

fun <T : TypedRealmObject> EmbeddedRealmObject.backlinks(sourceProperty: KProperty1<T, *>, sourceClass: KClass<T>): EmbeddedBacklinksDelegate<T>

Defines a backlink that represents a one-to-one inverse relationship between an EmbeddedRealmObject and a TypedRealmObject.

You cannot directly modify the backlink itself, it must be done on the pointing object. Usage example:

class Town : EmbeddedRealmObject {
val county: County by backlinks(County::towns)
}

class County : RealmObject {
val towns: RealmList<Town> = realmListOf()
}

Because an EmbeddedRealmObject class might be referenced by different TypedRealmObject than the defined by the backlinks. In such cases an exception would be thrown stating that the pointing object could not might not be able to resolve into a T value.

Return

delegate for the backlinks collection.

Parameters

T

type of object that references the model.

sourceProperty

property that references the model.

Throws

if the backlink is not of type T

inline fun <T : TypedRealmObject> EmbeddedRealmObject.backlinks(sourceProperty: KProperty1<T, *>): EmbeddedBacklinksDelegate<T>

Returns a BacklinksDelegate that represents the inverse relationship between two an EmbeddedRealmObject and a TypedRealmObject.

Reified convenience wrapper for EmbeddedRealmObject.backlinks.

fun <T : TypedRealmObject> RealmObject.backlinks(sourceProperty: KProperty1<T, *>, sourceClass: KClass<T>): BacklinksDelegate<T>

Defines a collection of backlinks that represents the inverse relationship between two Realm models. Any direct relationship, one-to-one or one-to-many, can be reversed by backlinks.

You cannot directly add or remove items from a backlinks collection. The collection automatically updates itself when relationships are changed.

backlinks on a one-to-one relationship:

class Town {
var county: County? = null
}

class County {
val towns: RealmResults<Town> by backlinks(Town::county)
}

backlinks on a one-to-many relationship:

class Parent : RealmObject {
var children: List<Child>? = null
}

class Child : RealmObject {
val parents: RealmResults<Parent> by backlinks(Parent::children)
}

Querying inverse relationship is like querying any RealmResults. This means that an inverse relationship cannot be null but it can be empty (length is 0). It is possible to query fields in the class containing the backlinks field. This is equivalent to link queries.

Because Realm lists allow duplicate elements, backlinks might contain duplicate references when the target property is a Realm list and contains multiple references to the same object.

Return

delegate for the backlinks collection.

Parameters

T

type of object that references the model.

sourceProperty

property that references the model.

inline fun <T : TypedRealmObject> RealmObject.backlinks(sourceProperty: KProperty1<T, *>): BacklinksDelegate<T>

Returns a BacklinksDelegate that represents the inverse relationship between two Realm models.

Reified convenience wrapper for RealmObject.backlinks.